package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"week2-project/model/es"
	"week2-project/model/mysql"
	"week2-project/request"
)

func VideoList(c *gin.Context) {
	var videoList request.VideoListReq
	if err := c.ShouldBindJSON(&videoList); err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code": 500,
			"msg":  "服务器内部错误",
			"err":  err.Error(),
		})
		return
	}
	data := mysql.Video{VideoTitle: videoList.VideoTitle}
	list, err := data.List(videoList.Keyword, videoList.Page, videoList.PageSize)
	light := es.HeightLight(data)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "列表展示失败",
			"err":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":   200,
		"msg":    "列表展示成功",
		"data":   list,
		"height": light,
	})
}
